/********************************************************/
/*	Copyright (C) 2016 Gong Li Bin			*/
/*	Project:	GlbKv-1.0.0			*/
/*	Author:		gong_libin			*/
/*	Date:		2013_09_18			*/
/*	File:		GlbKv.h				*/
/********************************************************/

#ifndef _GLBKV_H
#define	_GLBKV_H

#include "GlbPro.h"
#include "GlbSet.h"
#include "GlbUdp.h"
#include "GlbUtil.h"
#include "GlbFile.h"
#include "GlbTime.h"
#include "GlbTmap.h"
#include "GlbPool.h"
#include "GlbMulti.h"
#include "GlbThash.h"

#include <dirent.h>
#include <getopt.h>
#include <signal.h>

#define	GLB_KV_KEY			0x01
#define	GLB_KV_VAL			0x02
#define	GLB_KV_PAIR			0x02

#define	GLB_KV_SHM			0x7fffffff

#define	GLB_KV_FIELD			0x00
#define	GLB_KV_SLEEP			3600
#define	GLB_KV_MULTI			"238.6.10.12:20139"

#define	GLB_KV_LISTEN			"20911"
#define	GLB_KV_BUCKET			12582917ul;

#define	GLB_KV_GLOBAL			0x08
#define	GLB_KV_TIMEOUT			86400
#define	GLB_KV_VERSION			const_cast<char*>("GlbKv-1.0.0")

#define	GLB_KV_BAK			0x02
#define	GLB_KV_TTL			0x08
#define	GLB_KV_FILE			const_cast<char*>("GlbKvBackup.")
#define	GLB_KV_PATH			const_cast<char*>("/usr/local/")

#define	GLB_KV_INT			sizeof(int)
#define	GLB_KV_TIM			sizeof(time_t)
#define	GLB_KV_ULL			sizeof(ULONGLONG)
#define	GLB_KV_OFF			(GLB_KV_INT + GLB_KV_ULL + GLB_KV_TIM)

typedef struct tagGlbKvData
{
	int m_iLength;
	UCHAR* m_puszData;
	time_t m_ulStamp;
}GLBKVDATA_S;

void GlbKvQuit(int iSignal);
void GlbKvHelp(char* pszProc);
void* GlbKvAdmin(void* pNULL);
void* GlbKvMulti(void* pNULL);
void* GlbKvAccept(void* pNULL);
void GlbKvDelete(ULONGLONG ullKey);
int GlbKvCompare(const void* m, const void* n);
ULONGLONG GlbKvGetKey(GlbNet::GLBPROKV_S* pstKey);
UCHAR GlbKvInsert(ULONGLONG ullKey, GlbNet::GLBPROKV_S* pstVal);
UCHAR GlbKvSelect(ULONGLONG ullKey, GlbNet::GLBPROKV_S* pstVal);
UCHAR GlbKvParse(UCHAR* puszPacket, GlbNet::CGlbPro* pCPro, GlbNet::GLBPROKV_S* pstKv);

#endif /* _GLBKV_H */
